﻿@model List<RecipientInfoVM>
@{
    ViewBag.Title = "我的地址";
}

<div class="container">
    <div class="row">
        <aside class="col-sm-3">
            @Html.Partial("~/Views/Account/_AccountNav.cshtml")
        </aside>
        <section class="col-sm-9">
            <div class="panel panel-default">
                <div class="panel-heading">我的地址</div>
                <div class="panel-body">
                    <div class="well well-sm text-right">
                        @Ajax.RawActionLink("<i class='fa fa-plus fa-fw'></i>添加地址",
                        "Add", "RecipientInfo",
                        new { },
                        new AjaxOptions { HttpMethod = "Get", UpdateTargetId = "edit-container", OnComplete = "onAjaxComplete", OnSuccess = "OnSuccessLink" },
                        new { @class = "btn btn-primary" })
                     
                    </div>
                    <div class="row" id="addList">
                       @Html.Partial("_RecipientInfoList",Model)
                    </div>
                </div>
            </div>
            
            </section>
       
    </div>
</div>
<!-- /.container -->

<div id="edit-container">
</div>

<form id="anti-form" method="post">
    @Html.AntiForgeryToken()
</form>


@section footer {
    @Scripts.Render("~/bundles/jqueryvalWithBootstrap")

    <script>

        function OnSuccessLink(data) {
           // Common.ShowBox(data.Status, data.Message, "操作")
            $('#ModalEdit').modal();
        }

        function onAjaxComplete() {
            
        }
        function onBegin() {
            $("#btnSave i").removeClass("fa-save").addClass("fa-spinner fa-spin")
        }
        function onComplete() {
            $("#btnSave i").removeClass("fa-spinner fa-spin").addClass("fa-save")
           
        }

        function updateSuccess(data) {
            $('#ModalEdit').modal('hide');
            console.log($('#ModalEdit'));
          
            var title = '@ViewBag.Title';
            Common.ShowBoxWithFuncBack(data, title, submitSuccess);
            
        }

        function submitSuccess(id,htmlData) {         
            $("#addList").html(htmlData); 
        }


        $(function () {
            //active
            $(document).on("click", '.default-item', function (e) {
                e.preventDefault();

                var url = $(this).attr('data-url'), title = "设置默认", that = $(this);
                Common.SingleActionWithFuncBack(url, title, that, submitFunc);

            });

            function submitFunc(that, data) {
                // var tr = that.closest('.item-container').replaceWith(data);
                $("#addList").html(data);
            }


            $(document).on("change", '#PageSize', function (e) {
                e.preventDefault();

                var url = "@Url.Action("PageSizeSet")", title = "分页设置", pageSize = $(this).val();
                Common.PageSizeSet(url, title, pageSize, setPageSizeFunc);

            });

            function setPageSizeFunc() {
                location.reload();
            }

            //加载市/县
            $(document).on("change", '#ProvinceId', function () {
             
                var provinceId = $(this).val();
                var url = "@Url.Action("GetCity")";
                $.get(url, { provinceId: provinceId }, function (data) {
                    $("#CityId").html(data);
                });

            });
            //加载区镇
            $(document).on("change", '#CityId', function () {
               
                var cityId = $(this).val();
                var url = "@Url.Action("GetDistrict")";
                $.get(url, { cityId: cityId }, function (data) {
                    $("#DistrictId").html(data);
                });

            });

            //delete
            $(document).on("click", '.delete-item', function (e) {
                e.preventDefault();

                var url = $(this).attr('data-url');
                var that = $(this);
                bootbox.setLocale("zh_CN");
                bootbox.confirm("你确定要删除此项吗？", function (result) {
                    /*DELETE*/
                    if (result) {
                        var title = "@ViewBag.Title";
                        Common.DeleteItem(url, title, that);
                    }

                });

            });


        });
    </script>

}